Skip to content

fix: trigger pruning on tick #1086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2024
Merged

fix: trigger pruning on tick #1086

merged 4 commits into from
May 21, 2024

Conversation

avilagaston9
Copy link
Contributor

State pruning was not being triggered because checkpoint updates were occurring within the on_tick function, while only updates within the on_block function had been considered.

@avilagaston9 avilagaston9 marked this pull request as ready for review May 21, 2024 02:14
@avilagaston9 avilagaston9 requested a review from a team as a code owner May 21, 2024 02:14
last_finalized_key = slot |> root_by_slot_key()

with {:ok, it} <- Db.iterate(),
{:ok, @stateslot_prefix <> _slot, _value} <-
Exleveldb.iterator_move(it, last_finalized_key),
{:ok, slots_to_remove} <- get_slots_to_remove(it),
:ok <- Exleveldb.iterator_close(it) do
slots_to_remove |> Enum.map(&remove_by_slot/1)
slots_to_remove |> Enum.each(&remove_by_slot/1)
Logger.info("[StateDb] Pruning finished. #{length(slots_to_remove)} slots removed.")
end
end

defp get_slots_to_remove(slots_to_remove \\ [], iterator) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add typespec here? I am confused if slots are integers or binaries

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can create an issue to refactor this for clarity.

end
end

defp get_slots_to_remove(slots_to_remove \\ [], iterator) do
case Exleveldb.iterator_move(iterator, :prev) do
{:ok, @stateslot_prefix <> slot, _root} ->
[slot | slots_to_remove] |> get_slots_to_remove(iterator)
[slot |> :binary.decode_unsigned() | slots_to_remove] |> get_slots_to_remove(iterator)
Copy link
Collaborator

@MegaRedHand MegaRedHand May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can match this here by doing:

{:ok, @stateslot_prefix <> <<slot::unsigned-size(64)>>, _root} ->

end
end

@spec get_slots_to_remove(list(), :eleveldb.itr_ref()) :: {:ok, list(non_neg_integer())}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list of what?

@avilagaston9 avilagaston9 merged commit 87ba656 into main May 21, 2024
13 checks passed
@avilagaston9 avilagaston9 deleted the fix_states_pruning branch May 21, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants